Skip to content

feat: enforce key data controls and record token details - #85

Merged
ALikesToCode merged 8 commits into
mainfrom
feat/key-data-guards
Oct 20, 2026
Merged

ALikesToCode merged 8 commits into
mainfrom
feat/key-data-guards

Conversation

@ALikesToCode

@ALikesToCode ALikesToCode commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Keys can require official provider classes and enforce OpenRouter preferences for an app whose requests carry personal data. Direct non-official calls return 403 provider_class_not_allowed; automatic, cascade and managed routes filter concrete candidates. The Limits form and key-controls API expose both controls. Forced values override caller preferences while retaining a caller's data_collection: "deny".

Provider HTTP and SDK dispatch now share one admission boundary per runtime: services/provider_dispatch.py and worker/provider-dispatch.mjs. Every send rereads current durable controls. The version-1 data_policy envelope requires both explicit fields; absent, malformed or unsupported policies, missing accounts and store outages refuse dispatch. Bootstrap administrative recovery remains separate from generation authority. Restricted requests select the operator's current attested credential after adapters, pooling and fallback selection; cached credentials cannot recover a missing binding.

The boundaries cover native and unified protocols, media creation and retrieval, video polling and watches, audio, embeddings, async and batch execution, Realtime, roleplay, shadow evaluation, intelligence and Knowledge/MCP. Deferred work retains identity and rereads policy. Knowledge ingestion and imported-skill watches retain their source account across scheduling and retries; legacy ownerless imports refuse upstream checks until explicitly imported again. Realtime checks ticket issuance and socket admission. Realtime and roleplay refuse forced preferences because those complete transports cannot enforce them. Controlled requests are excluded from shadow sampling, and replay rechecks its source before candidate and judge dispatch. Restricted paid-tier requests reject caller credential overrides and use only the current attested operator binding.

Credential injection is limited to each provider's allowlisted API origins. Public video assets remain policy-admitted but receive no API credentials, including during relay and storage copying. Downloads follow at most five HTTPS redirects, rechecking admission at every hop and permanently stripping credential headers after an origin change. Unresolved redirects fail instead of returning redirect pages as video. Vertex resolves a fresh token from the current operator service-account or OAuth binding; missing, malformed or changed bindings refuse dispatch.

The static inventory now pins every runtime source module independently of transport spelling. A session-wide socket audit hook covers Python connections, including extension sockets. Worker guards cover fetch, Node HTTP and socket transports; replacing fetch in tests retains the guard. Provider SDK and index binding doubles share a factory that checks admission on every method, nested handle and replacement method. Capabilities exist only during admitted operations and are revoked after success or failure. Mutation regressions exercise alternate clients from unlisted modules, extension-socket connects, and removal of both provider SDK admission wrappers. Separate control traffic uses destination-bound scopes; disposable D1 fixtures register only their own loopback ports. Private persistence, storage management, authentication, telemetry, public capability metadata and webhook delivery remain separate from provider generation.

Provider-reported cached input and reasoning tokens persist in events and per-key/model totals. The Usage page displays cache-hit percentage and reasoning tokens. Unreported event details remain null; cache-hit percentage is cached input divided by all recorded input in the group. The optional budget webhook is omitted.

Rollout: apply 0041_key_data_guards.sql, 0042_usage_token_details.sql and 0043_integration_data_policy.sql through the migration runner; deploy the matching Worker, including the private Knowledge Worker; deploy the Container; enable controls last. Existing keys remain unrestricted until configured. Mixed-version responses fail closed. The unmigrated-account fixture excludes the dependent ALTER migrations and retains its refusal assertions. This branch starts independently from main.

Provider classification and evidence are documented in key data controls. Uncertainties: chutes/nineteen use conservative reseller tags; local runners and legacy aliases use conservative free tags; relay/pool sourcing and current terms remain unverified; hyperbolic's historical inference endpoint needs availability confirmation. Paid-tier classification requires operator attestation of the configured credential.

Validation: Full Python, Worker and local D1 integration suites passed through the shared test lock (5,275 Python tests plus 975 subtests, with 2 skipped; 1,954 Worker tests; 7 integration tests). Integration explicitly selected the virtualenv Python. Credential-origin, relay/storage redirects, runtime bypass mutations and current Vertex binding regressions passed. Disabling socket auditing broke both extension-socket regressions; removing the two SDK admission wrappers broke seven of the eight original binding tests. Fatal lint, type checks across 290 source files, static secret scans, whitespace checks, and confidentiality and publication-attribution greps passed. No deployment or remote migration was performed.

Existing oversized files retain scoped integration changes: services/auth_service.py (1,261 lines), services/proxy_service.py (3,437 lines), and tests/test_cloudflare_worker.mjs (4,165 lines). Admission lives in separate modules. Safe follow-up boundaries are account SQL persistence, provider transport orchestration, and protocol-specific Worker fixtures, respectively. Extracting those unrelated responsibilities here would expand the security change.

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b497647a-9a85-46de-9f3f-83928f1b1565
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
multillm-proxy 8b67b1d Oct 20 2026, 11:12 AM

@ALikesToCode
ALikesToCode marked this pull request as ready for review October 20, 2026 11:19
@ALikesToCode
ALikesToCode merged commit f073401 into main Oct 20, 2026
6 of 7 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T11:20:29.219848Z 8b67b1d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant